/**   
 * @Title: LotteryInfoCommunicater.java 
 * @Package com.esun.network.communicater 
 * @Description: (开奖信息通讯类) 
 * @Author Billy qigs@500wan.com   
 * @Date 2011-6-20 上午10:34:08  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.network.communicater;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.LotteryInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: LotteryInfoCommunicater
 * @Description: (获取开奖信息)
 * @author City Jiangsy@500wan.com
 * @date 2011-6-16 下午02:26:04
 * 
 */
public class LotteryInfoCommunicater extends ServerCommunicater {

	private String msgServer;

	private ArrayList<LotteryInfo> alLotteryInfo = new ArrayList<LotteryInfo>();
	private boolean isSucceed = false;

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	// 返回开奖信息
	public ArrayList<LotteryInfo> getLotteryInfoList() {
		int count = super.getListResult().size();

		for (int i = 0; i < count; i++) {
			LotteryInfo lotteryInfo = new LotteryInfo();
			lotteryInfo.setExpect(super.getListResult().get(i).get(Key.KEY_EXPECT));
			lotteryInfo.setLotteryNum(super.getListResult().get(i).get(Key.KEY_LOTT_OPENCODE));
			lotteryInfo.setLotid(super.getListResult().get(i).get(Key.KEY_LOTID));
			lotteryInfo.setOpentime(super.getListResult().get(i).get(Key.KEY_OPENTIME));
			alLotteryInfo.add(lotteryInfo);
		}
		return alLotteryInfo;
	}

	/**
	 * @throws SAXException
	 * @throws ParserConfigurationException
	 * @throws IOException
	 * @throws ClientProtocolException
	 * @Title: isGetHistoryLotInfo
	 * @Description: (获取当前开奖信息接口 业务编号10010)
	 * @param @return isSucceed
	 * @return boolean 返回类型
	 * @throws
	 */
	public boolean isGetHistoryLotInfo(String lotid, String expect, String recordsinpage) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_GET_DIGIT_LOTTERY_HISTORY_INFO));
		list.add(mapItem(BussinessCode.PASER_CK, Config.NULLMARK));
		list.add(mapItem(Key.KEY_LOTID, lotid));
		list.add(mapItem(Key.KEY_EXPECT, expect));
		list.add(mapItem(Key.KEY_RECORDSINPAGE, recordsinpage));

		super.getServerResponse(list, true);
		setMsgServer(super.getServerMsg());
		if (super.getState() == 100) {
			isSucceed = true;
			if (super.getListResult().size() == 0) {
				isSucceed = false;
				setMsgServer("没有更多记录");
			}
		} else {
			isSucceed = false;
		}
		return isSucceed;
	}

	/**
	 * @Title: mapItem
	 * @Description: (工具类,用于构建AraayList单条内容)
	 * @param @param name 参数名
	 * @param @param value 参数值
	 * @param @return map
	 * @return HashMap<String,String> 返回类型
	 * @throws
	 */
	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

}
